-- <nowiki>
local T = require('Module:Tool')
local TR = require('Module:Trans')
local V = require('Module:Value')
local G = require('Module:Template/G')

local tableAdaptive = {
    Physical = '攻击力',
    Magic = '法术强度'
}

return {
    render = function(frame)
        local args = T.parseArgs(frame)

        local champion = args.champion or args[2] or V.champion({[1] = args.slot or args[1], [2] = '~'})

        if champion == nil then
            return T.error(
                '[Template.Champion.Header.render().champion] is Nil: ' .. T.parseErrorValue(args.slot or arg[1])
            )
        end

        local divResult = mw.html.create('div')
        divResult:addClass('LOLContent'):addClass('TemplateChampionHeader')

        local divMask = mw.html.create('div')
        divMask:addClass('Mask')
        divResult:wikitext(tostring(divMask))

        local divBackground = mw.html.create('div')
        divBackground:addClass('Background')
        divBackground:wikitext(string.format('[[File:Splash-%s.jpg]]', champion.slot))
        divResult:wikitext(tostring(divBackground))

        local tableInfo = mw.html.create('table')
        tableInfo:addClass('InfoTable')

        -- 头像/名称/称号
        local trHeader = mw.html.create('tr')
        local tdHeader = mw.html.create('td')

        local divHeader = mw.html.create('div')
        local spanName = mw.html.create('span')
        local spanTitle = mw.html.create('span')
        divHeader:addClass('Header'):wikitext(string.format('[[File:Header-Square-%s.png|50px]]', champion.slot))
        spanName:addClass('Name'):wikitext(champion.name)
        spanTitle:addClass('Title'):wikitext(champion.title)

        tdHeader:wikitext(tostring(divHeader))
        tdHeader:wikitext(tostring(spanName))
        tdHeader:wikitext('<br />')
        tdHeader:wikitext(tostring(spanTitle))

        trHeader:wikitext(tostring(tdHeader))

        tableInfo:wikitext(tostring(trHeader))

        -- 定位
        local trLabelRole = mw.html.create('tr')
        local thLabelRole = mw.html.create('th')
        thLabelRole:addClass('Label'):wikitext('定位：')
        trLabelRole:wikitext(tostring(thLabelRole))
        tableInfo:wikitext(tostring(trLabelRole))

        local trRole = mw.html.create('tr')
        local tdRole = mw.html.create('td')
        tdRole:addClass('Value')

        for i, slotRole in ipairs(champion.type.roles) do
            tdRole:wikitext(G.render({slotRole}))

            if i < #champion.type.roles then
                tdRole:wikitext(' | ')
            end
        end

        trRole:wikitext(tostring(tdRole))
        tableInfo:wikitext(tostring(trRole))

        -- 次要属性
        local trLabelAttr2 = mw.html.create('tr')
        local thLabelAttr2 = mw.html.create('th')
        thLabelAttr2:addClass('Label'):wikitext('次要属性：')
        trLabelAttr2:wikitext(tostring(thLabelAttr2))
        tableInfo:wikitext(tostring(trLabelAttr2))

        local trAttr2 = mw.html.create('tr')
        local tdAttr2 = mw.html.create('td')
        tdAttr2:addClass('Value')

        tdAttr2:wikitext(G.render({champion.type.range})):wikitext(' | ')
        tdAttr2:wikitext(G.render({'AdaptiveForce', tableAdaptive[champion.type.adaptive]})):wikitext(' | ')

        for i, slotResource in ipairs(champion.type.resource) do
            tdAttr2:wikitext(G.render({slotResource}))

            if i < #champion.type.resource then
                tdAttr2:wikitext(' | ')
            end
        end

        trAttr2:wikitext(tostring(tdAttr2))
        tableInfo:wikitext(tostring(trAttr2))

        -- 价格
        local trLabelPrice = mw.html.create('tr')
        local thLabelPrice = mw.html.create('th')
        thLabelPrice:addClass('Label'):wikitext('价格：')
        trLabelPrice:wikitext(tostring(thLabelPrice))
        tableInfo:wikitext(tostring(trLabelPrice))

        local trPrice = mw.html.create('tr')
        local tdPrice = mw.html.create('td')
        tdPrice:addClass('Value')

        tdPrice:wikitext(G.render({'BlueEssence', champion.price.be})):wikitext(' | ')
        tdPrice:wikitext(G.render({'RiotPoints', champion.price.rp}))

        trPrice:wikitext(tostring(tdPrice))
        tableInfo:wikitext(tostring(trPrice))

        -- 上线时间
        local trLabelRelease = mw.html.create('tr')
        local thLabelRelease = mw.html.create('th')
        thLabelRelease:addClass('Label'):wikitext('上线时间：')
        trLabelRelease:wikitext(tostring(thLabelRelease))
        tableInfo:wikitext(tostring(trLabelRelease))

        local trRelease = mw.html.create('tr')
        local tdRelease = mw.html.create('td')
        tdRelease:addClass('Value')

        tdRelease:wikitext(champion.release.date)

        trRelease:wikitext(tostring(tdRelease))
        tableInfo:wikitext(tostring(trRelease))

        -- 最后更新
        local trLabelChanges = mw.html.create('tr')
        local thLabelChanges = mw.html.create('th')
        thLabelChanges:addClass('Label'):wikitext('最后更新：')
        trLabelChanges:wikitext(tostring(thLabelChanges))
        tableInfo:wikitext(tostring(trLabelChanges))

        local trChanges = mw.html.create('tr')
        local tdChanges = mw.html.create('td')
        tdChanges:addClass('Value')

        tdChanges:wikitext(champion.release.changes)

        trChanges:wikitext(tostring(tdChanges))
        tableInfo:wikitext(tostring(trChanges))

        divResult:wikitext(tostring(tableInfo))

        return TR.s({tostring(divResult)})
    end
}
-- </nowiki>
-- [[Category:Module/Template]]
